<template>
    <div>
        <el-card class="box-card" shadow="never">
            <i class="el-icon-search"></i>
            <span>筛选搜索</span>
            <el-row :gutter="10" style="margin-top:15px;">
                <el-col :span='6'>
                    <el-input v-model="car_no">
                      <template slot="prepend">车牌号</template>
                    </el-input>
                 </el-col>
                 <el-col :span="6">
                    <el-input v-model="shop_name">
                      <template slot="prepend">店铺名称</template>
                    </el-input>
                </el-col>
                <el-col :span="4">
                  <el-date-picker
                        style="width:100%"
                        v-model="start_date"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="申领起始日期">
                      </el-date-picker>
                 </el-col>
                 <el-col :span="4">
                   <el-date-picker
                         style="width:100%"
                         v-model="end_date"
                         type="date"
                         value-format="yyyy-MM-dd"
                         placeholder="申领截止日期">
                   </el-date-picker>
                  </el-col>
            </el-row>
            <el-row :gutter="10" style="margin-top:15px;">
                <el-col :span='6'>
                    <el-input v-model="owner_tel_no">
                      <template slot="prepend">申领手机号</template>
                    </el-input>
                 </el-col>
                 <el-col :span='6'>
                     <el-input v-model="lt_bar_code">
                       <template slot="prepend">轮胎条码</template>
                     </el-input>
                  </el-col>
                <el-col :span="6">
                  <el-select v-model="status" placeholder="理赔状态" clearable>
                      <el-option
                        v-for="item in allstatus"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                  </el-select>
                </el-col>
            </el-row>
            <el-row :gutter="20" class="yx_el_row">
                <el-col :span="4">
                    <el-button type="success" plain @click="search">筛选</el-button>
                    <!--<ExcelImport style="display:inline-block;margin-left:10px" :post_url="excel_post_url" :show_file_list="show_file_list" :accept_str="accept_str" :handle_result="handle_result"></ExcelImport>-->
                </el-col>
            </el-row>
            <div class="yx_line"></div>
            <div style="margin-top:10px;">
              <i class="el-icon-tickets"></i>
              <span>数据列表</span>
            </div>
            <el-table class="yx_table" border :data="tyrelist">
                <el-table-column type="index" label="序号" width="80">
                </el-table-column>
                <el-table-column prop="car_no" label="车牌号" width="100">
                </el-table-column>
                <el-table-column prop="customer_name" label="车主姓名" width="120">
                </el-table-column>
                <el-table-column prop="owner_tel_no" label="车主手机号" width="120">
                </el-table-column>
                <el-table-column prop="shop_name" label="门店名称" width="250">
                </el-table-column>
                <el-table-column prop="shop_code" label="门店代码" width="150">
                </el-table-column>
                <el-table-column prop="lt_bar_code" label="轮胎条码" width="100">
                </el-table-column>
                <el-table-column prop="lt_product_code" label="轮胎产品码" width="100">
                </el-table-column>
                <el-table-column prop="year_week" label="年周" width="90">
                </el-table-column>
                <el-table-column prop="lt_apply_time" label="申领时间" width="200">
                </el-table-column>
                <el-table-column prop="status" label="状态">
                </el-table-column>
            </el-table>
            <Pagination :total_count="total_count" :getList="getList"></Pagination>
        </el-card>
    </div>
</template>

<script>
    import { getTyreList,getProvinceList } from '@/api/tyre.js';
    import Pagination from '@/components/Pagination.vue';
    import ExcelImport from '@/components/ExcelImport.vue';
    export default {
        name: 'TyreList',
        components:{ Pagination,ExcelImport },
        inject:['reload'],
        data() {
            return {
                tyrelist:[],
                total_count:0,
                car_no:'',
                shop_name:'',
                start_date:'',
                end_date:'',
                owner_tel_no:'',
                lt_bar_code:'',
                status:'',
                //excel
                excel_post_url:'/import-tyre-list',
                show_file_list:false,
                accept_str:".csv",
                allstatus:[
                  {value:'0',label:'未理赔'},
                  {value:'1',label:'已理赔'},
                  {value:'2',label:'已拒赔'}
                ]
            }
        },
        methods: {
            getList(current_page,page_size){
                this.$store.dispatch('loadCurrentPageSize',page_size);
                var send_data={
                    current_page:current_page,
                    page_size:page_size,
                    car_no:this.car_no,
                    shop_name:this.shop_name,
                    start_date:this.start_date,
                    end_date:this.end_date,
                    owner_tel_no:this.owner_tel_no,
                    lt_bar_code:this.lt_bar_code,
                    status:this.status
                }
                let that=this;
                getTyreList(send_data).then(function(response){
                    if(response.data.code==1){
                      that.tyrelist=response.data.list;
                      that.total_count=response.data.total_count;
                    }
                });
            },
            search(){
               this.getList(1,this.$store.getters.getCurrentPageSize);
            },
            add(){
                this.$router.push({
                    name:'tyreEdit',
                    params:{id:-1,edit_type:1}
                });
            },
            edit(id,edit_type){
                this.$router.push({
                    name:'tyreEdit',
                    params:{id:id,edit_type:edit_type}
                });
            },
            del(id){
                let that=this;
                this.$confirm('确认删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then((e) => {
                    var send_data={
                        id:id,
                        is_delete:1
                    };
                    delTyre(send_data).then(function(response){
                        let type=response.data.code==1?'success':'error';
                        that.$message({
                            message:response.data.msg,
                            type:type,
                            onClose:function(e){
                                that.reload();
                            }
                        });
                    })
                })
            },
            //处理excel导入的结果
            handle_result(res){
               let that=this;
               let type=res.code==1?'success':'error';
               this.$message({
                   message:res.msg,
                   type:type,
                   onClose:function(e){
                      if(res.code==1){
                        that.reload();
                      }
                   }
               });
            },
        },
        created() {
            this.getList(1,this.$store.state.default_page_size);
        },
    }
</script>
